package com.jstorm.count.controller.commonroad;

import com.jstorm.count.dto.CommonExecution;
import com.jstorm.count.dto.ResultDtoUtile;
import com.jstorm.count.pojo.Result;
import com.jstorm.count.service.commonroad.CommonroadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ProjectName: springboot-mybatis
 * @Package: com.jstorm.count.controller.network
 * @ClassName: CommonroadController
 * @Description:
 * @Author: Mr_hu
 * @CreateDate: 2018/12/29 10:08
 * ***********************************************************
 * @UpdateUser: Mr_hu
 * @UpdateDate: 2018/12/29 10:08
 * @UpdateRemark: The modified content
 * @Version: 1.0
 * ***********************************************************
 * Copyright: Copyright (c) 2018
 **/
@Controller
@ResponseBody
public class CommonroadController {

    @Autowired
    private CommonroadService commonroadService;

    /**
     * 共路信令数量统计
     * @return
     */
    @RequestMapping("/commonroad/commonroad-count")
    public ResultDtoUtile CommonroadCount(){
        CommonExecution commrondExecution = commonroadService.selectNumber();

        if (commrondExecution == null){
            new ResultDtoUtile(commrondExecution.getCode(),commrondExecution.getMsg());
        }

        //返回成功
        return new ResultDtoUtile(commrondExecution.getCode(),commrondExecution.getMsg(),commrondExecution.getList());
    }


    /**
     * 共路信令数量统计
     * @return
     */
    @RequestMapping("/commonroad/commonroad-total")
    public ResultDtoUtile CommonroadTotal(){
        //进行service方法查找所有
        CommonExecution commonroadTotal = commonroadService.selectTotal();
        //返回失败，没有数据，或者出错了
        if (commonroadTotal == null){
            new ResultDtoUtile(commonroadTotal.getCode(),commonroadTotal.getMsg());
        }
        //返回成功
        //返回成功
        return new ResultDtoUtile(commonroadTotal.getCode(),commonroadTotal.getMsg(),commonroadTotal.getList());
    }

    @RequestMapping("/sums")
    public Result Total(){
        /**计算总数**/
        try {
            return Result.isOk().data(commonroadService.selectSums());
        } catch (Exception e) {
            return Result.isFail(e);
        }
    }


}
